﻿using IntoLog;
using IntoStationSystem.Dialog;
using System;
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace IntoStationSystem.Global
{
    public class Funcs
    {
        /// <summary>
        /// 显示UserControl
        /// </summary>
        /// <param name="name"></param>
        public static void ShowUserControl(string name)
        {
            string fullName = $"IntoStationSystem.Views.{name}";
            UserControl user = null;
            if (name == "LogView")
            {
                fullName = "IntoLog.LogView";
                user = new LogView();
            }
            else
            {
                user = Activator.CreateInstance(Type.GetType(fullName)) as UserControl;
            }
            string title = Fields.ViewNames.ContainsKey(name) ? Fields.ViewNames[name] : "NULL";
            if (user != null)
            {
                MainDialog dialog = new MainDialog(title);
                dialog.Width = 1300;
                dialog.Height = user.Height + 30;
                dialog.main.Children.Add(user);
                dialog.ShowDialog();
            }
        }
        /// <summary>
        /// 从文件获取BitmapImage
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static BitmapImage BitmapImageFromFile(string file)
        {
            BitmapImage bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = new Uri(file);
            bitmap.EndInit();
            return bitmap;
        }
        /// <summary>
        /// 打开系统软键盘
        /// </summary>
        public static void ShowSoftKeyboard()
        {
            Process pro = new Process();
            pro.StartInfo.FileName = @"C:\Windows\System32\osk.exe";
            pro.Start();
        }
    }
}
